<?php
// debug.php - 诊断页面
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

// 检查CSS文件
$cssFile = 'css/style.css';
$cssExists = file_exists($cssFile);
$cssReadable = $cssExists ? is_readable($cssFile) : false;

// 检查data目录
$dataDir = 'data';
$dataExists = file_exists($dataDir);
$dataWritable = $dataExists ? is_writable($dataDir) : false;

// 检查JSON文件
$jsonFile = 'data/products.json';
$jsonExists = file_exists($jsonFile);
$jsonReadable = $jsonExists ? is_readable($jsonFile) : false;
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Debug - System Check</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 2rem; }
        .check { margin: 1rem 0; padding: 1rem; border-radius: 8px; }
        .success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
        .warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
        .error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
        .info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
    </style>
</head>
<body>
    <h1>系统诊断</h1>
    
    <div class="check <?php echo $cssExists && $cssReadable ? 'success' : 'error'; ?>">
        <h3>CSS文件检查</h3>
        <p>文件路径: <?php echo $cssFile; ?></p>
        <p>状态: <?php echo $cssExists ? '存在' : '不存在'; ?></p>
        <p>可读性: <?php echo $cssReadable ? '可读' : '不可读'; ?></p>
    </div>

    <div class="check <?php echo $dataExists ? 'success' : 'warning'; ?>">
        <h3>数据目录检查</h3>
        <p>目录路径: <?php echo $dataDir; ?></p>
        <p>状态: <?php echo $dataExists ? '存在' : '不存在'; ?></p>
        <p>可写性: <?php echo $dataWritable ? '可写' : '不可写'; ?></p>
    </div>

    <div class="check <?php echo $jsonExists && $jsonReadable ? 'success' : 'warning'; ?>">
        <h3>JSON文件检查</h3>
        <p>文件路径: <?php echo $jsonFile; ?></p>
        <p>状态: <?php echo $jsonExists ? '存在' : '不存在'; ?></p>
        <p>可读性: <?php echo $jsonReadable ? '可读' : '不可读'; ?></p>
    </div>

    <div class="check info">
        <h3>PHP信息</h3>
        <p>PHP版本: <?php echo phpversion(); ?></p>
        <p>错误显示: <?php echo ini_get('display_errors') ? '开启' : '关闭'; ?></p>
        <p>当前路径: <?php echo __DIR__; ?></p>
    </div>

    <div class="check info">
        <h3>测试链接</h3>
        <p><a href="index.php">首页</a></p>
        <p><a href="products.php">产品页面</a></p>
        <p><a href="admin/login.php">管理员登录</a></p>
    </div>
</body>
</html>